package com.company.project.controller.ldjsc.robot;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.company.project.entity.ldjsc.robot.FaultqaEntity;
import com.company.project.service.ldjsc.robot.FaultqaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.List;

import com.company.project.common.utils.DataResult;


/**
 * @author wenbin
 * @email *****@mail.com
 * @date 2025-07-10 11:11:34
 */
@Controller
@RequestMapping("/sxzy/robot")
public class FaultqaController {
    @Autowired
    private FaultqaService faultqaService;

    /**
     * 跳转到页面
     */
    @GetMapping("/index/faultqa")
    public String faultqa() {
        return "faultqa/list";
    }


    @ApiOperation(value = "查询分页数据")
    @PostMapping("faultqa/listByPage")
    @SaCheckPermission("faultqa:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody FaultqaEntity faultqa) {
        LambdaQueryWrapper<FaultqaEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        queryWrapper.eq(faultqa.getId() != null, FaultqaEntity::getId, faultqa.getId());
        queryWrapper.orderByDesc(FaultqaEntity::getId);
        IPage<FaultqaEntity> iPage = faultqaService.page(faultqa.getQueryPage(), queryWrapper);
        return DataResult.success(iPage);
    }


    @ApiOperation(value = "新增")
    @PostMapping("faultqa/add")
//    @SaCheckPermission("faultqa:add")
    @ResponseBody
    public DataResult add(@RequestBody FaultqaEntity faultqa) {

        if (StringUtils.isBlank(faultqa.getQuestion()) ||
                StringUtils.isBlank(faultqa.getQuestion()) ||
                StringUtils.isBlank(faultqa.getUserid())) {
            return DataResult.fail("参数异常！");
        }
        faultqaService.save(faultqa);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("faultqa/delete")
    @SaCheckPermission("faultqa:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) {
        faultqaService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("faultqa/update")
    @SaCheckPermission("faultqa:update")
    @ResponseBody
    public DataResult update(@RequestBody FaultqaEntity faultqa) {
        faultqaService.updateById(faultqa);
        return DataResult.success();
    }


}
